# ===获得币对精度
import math

import numpy as np
import pandas as pd
from Config import *


# =====获取现货、U本位合约、币本位合约交易对比价精度和数量精度=====
def usdt_future_exchange_info(symbol, trade_type):
    exchange_info = []
    # 现货
    if trade_type == ('spot' or 'SPOT'):
        # 获取现货交易规则和交易对
        # GET /fapi/v1/exchangeInfo
        exchange_info = exchange.publicGetExchangeInfo()
    # U本位合约
    elif trade_type == ('usdt' or 'USDT'):
        # 获取u本位合约交易规则和交易对
        # GET /fapi/v1/exchangeInfo
        exchange_info = exchange.fapiPublicGetExchangeInfo()
    # 币本位合约
    elif trade_type == ('coin' or 'COIN'):
        # 获取币本位合约交易规则和交易对
        # GET /dapi/v1/exchangeInfo
        exchange_info = exchange.dapiPublicGetExchangeInfo()
    df = pd.DataFrame(exchange_info['symbols'])
    filters = pd.DataFrame(df.loc[df['symbol'] == symbol, 'filters'].iloc[0])
    tick_size = float(filters.loc[filters['filterType'] == 'PRICE_FILTER', 'tickSize'].iloc[0])
    price_precision = int(math.log(tick_size, 0.1))
    step_size = float(filters.loc[filters['filterType'] == 'LOT_SIZE', 'stepSize'].iloc[0])
    quantity_precision = int(math.log(step_size, 0.1))
    return price_precision, quantity_precision


